package tds.study.payment.service.impl;

import tds.study.payment.entity.Payment;
import tds.study.payment.mapper.PaymentMapper;
import tds.study.payment.service.IPaymentService;
import tds.study.payment.pojo.query.PaymentQuery;
import tds.study.payment.pojo.vo.PaymentVo;
import tds.study.payment.pojo.dto.DeleteDto;
import tds.study.payment.pojo.dto.add.PaymentAddDto;
import tds.study.payment.pojo.dto.update.PaymentUpdateDto;
import tds.study.payment.pojo.vo.PageVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tds
 * @since 2021-11-09
 */
@Service
public class PaymentServiceImpl extends ServiceImpl<PaymentMapper, Payment> implements IPaymentService {

    /**
    * 的分页查询
    *
    * @param query
    * @return
    */
    @Override
    public PageVo<PaymentVo> queryPage(PaymentQuery query) {
        // todo 其他业务逻辑
        // 开启分页查询
        PageHelper.startPage(query.getPageNum(), query.getPageSize());
        List<PaymentVo> vos = getBaseMapper().queryAll(query);
        PageInfo<PaymentVo> pageinfo = new PageInfo<>(vos);
        return new PageVo(pageinfo);
    }

    /**
    * 新增
    *
    * @param addDto
    */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void save(PaymentAddDto addDto) {
        // todo 其他业务逻辑
        Payment addDo = new Payment();
        BeanUtil.copyProperties(addDto, addDo);
        this.save(addDo);
    }

    /**
    * 修改
    *
    * @param updateDto
    */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void update(PaymentUpdateDto updateDto) {
        // todo 其他业务逻辑
        Payment updateDo = new Payment();
        BeanUtil.copyProperties(updateDto, updateDo);
        this.updateById(updateDo);
    }

    /**
    * 删除多条
    *
    * @param deleteDto
    */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(DeleteDto deleteDto) {
        // todo 其他业务逻辑
        if (CollUtil.isEmpty(deleteDto.getIds())) {
            return;
        }
        this.removeByIds(deleteDto.getIds());
    }
}
